package com.itheima.controller;

import com.itheima.entity.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/student")
public class StudentController {

    @Autowired
    private StudentService studentService;


    /*查找所有*/
    @GetMapping
    public Object findAll() {
        return studentService.findAll();

    }

    /*根据id查找*/
    @GetMapping(value = "/{id}")
    public Object findById(@PathVariable(value = "id") Integer id) {
        return studentService.findById(id);

    }

    /*根据id删除*/
    @DeleteMapping(value = "/{id}")
    public Object deleteById(@PathVariable(value = "id") Integer id) {

        return studentService.deleteById(id);
    }


    /*添加信息*/
    @PostMapping
    public Object add(@RequestBody Student student) {

        return studentService.add(student);


    }

    /*更新学生信息*/
    @PutMapping
    public Object update(@RequestBody Student student) {

        return studentService.update(student);

    }

}
